<?php
  require_once('tpl/header.php');
?><?php 
      require_once("loginCheckadmin.php");
      require_once("../system/dbConn.php");
 
     ?>
  <form action="">
    	<input type="text" name="key">
    	<input type="submit" value="搜索">
    </form>

 

	<?php 
	//连接数据库：读取users表中的所有记录，显示到表格中



	$sql = "select * from demand";
    
    if(isset($_GET["key"])){ 
       $key=trim($_GET["key"]);
       $sql="select * from demand where name like '%{$key}%'";
    }
    
	$result = mysqli_query($link,$sql);
//结果集
	$num = mysqli_num_rows($result);
	if($num==0){
		echo "没有记录，请重新输入";
		exit();
	}
	?>
	<table class="table table-bordered" align="center" width="60%">
		<caption>任务列表（共 <?php echo $num ?> 个任务）</caption>
		<tr>
			<th width="5%">任务编号</th>
			<th width="15%">任务名称</th>
			<th width="10%">任务类型</th>
			<th width="15%">时限</th>
			<th width="5%">报酬</th>
			<th width="20%">备注</th>
			<th width="10%">发布时间</th>
			<th width="15%">发布人</th>
			<th width="5%">操作</th>
		</tr>
	<?php
	while ($row = mysqli_fetch_assoc($result)) {
	?>
		<tr>
			<th><?php echo $row["id"]; ?></th>
			<th><?php echo $row["name"] ?></th>
			<th>
				<?php 
				// echo $row["gender"];
				if ($row["type"] == 0) {
					echo "寻找失物";
				}else if ($row["type"] == 1){
					echo "物品借用";
				}else if ($row["type"] == 2){
					echo "疑惑解答";
				}else if ($row["type"] == 3){
					echo "电脑修理";
				}else echo "其他";
				?>		
			</th>
			<th>
				<?php 
				// echo $row["gender"];
				if ($row["time"] == 0) {
					echo "5min之内";
				}else if ($row["time"] == 1){
					echo "5~15min";
				}else if ($row["time"] == 2){
					echo "15~30min";
				}else if ($row["time"] == 3){
					echo "一天以内";
				}else echo "一周以内";
				?>		
			</th>
			<th><?php echo $row["money"] ?></th>
			<th><?php echo $row["details"] ?></th>
			<th><?php echo $row["uploaddate"] ?></th>
			<th><?php echo $row["uploadusers"] ?></th>
			<th ><a href="doDemandDelete.php?id=<?php echo $row["id"];?>" 
				onclick="return confirm('真的删除吗?')">删除</a></th>
		</tr>
	<?php	
	}
	 	?>
		</table>
	</form>
   


<?php
  require_once('tpl/footer.php');
?>